<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> 
<html>
<head>
<title>客户信息列表</title>
<link href="<%=path1%>/css/css.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/redmond/jquery-ui-1.8.2.custom.css"/>
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/ui.jqgrid.css"/> 
<script type="text/javascript" src="<%=path1%>/scripts/jquery-1.7.2.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

	  var SearchSql ="GROUP BY w.order_type,p.pay_type_name,customer_name";
			 $.ajax({
				 url:"./Order/selectBySql.do",
				 data:{'SearchSql':SearchSql},
				 success:function(data){
					 
					 var selectscustomerName = document.getElementById("customer_name");
			         var selectsOrderType = document.getElementById("order_type");
			         var selectsPayTypeName = document.getElementById("pay_type_name");
			        for(var a=0;a<data.rows.length;a++){
			         	var opCustomerName=document.createElement("option");      
			         	opCustomerName.setAttribute("value",data.rows[a].customer_name);        
			         	opCustomerName.appendChild(document.createTextNode(data.rows[a].customer_name)); 
			        	selectscustomerName.appendChild(opCustomerName);      
			        	//------------
			        		var opselectsPayTypeName=document.createElement("option");    
			        		opselectsPayTypeName.setAttribute("value",data.rows[a].pay_type_name);        
			        		opselectsPayTypeName.appendChild(document.createTextNode(data.rows[a].pay_type_name)); 
			        		selectsPayTypeName.appendChild(opselectsPayTypeName);  
			        	    
			        	//---------------
			           var opselectsOrderType=document.createElement("option"); 
			         	opselectsOrderType.setAttribute("value",data.rows[a].order_type);        
			         	opselectsOrderType.appendChild(document.createTextNode(data.rows[a].order_type)); 
			         	selectsOrderType.appendChild(opselectsOrderType);         
			        }
			       
			      
				 }
			 });
});
function loadorder(){
    sstrval = $("#order_type").val();
	customerNameVal = $("#customer_name").val();
	payTypeName = $("#pay_type_name").val();
	var sstra ='';
	if(!(sstrval == '' || sstrval == null )){
		sstra = "and order_type ='"+sstrval+"'";
	}
	if(!(customerNameVal == '' || customerNameVal == null) ){
		sstra = sstra+ "and customer_name ='"+customerNameVal+"'";
	}
	if(!(payTypeName == '' || payTypeName == null )){
		sstra = sstra+ "and pay_type_name ='"+payTypeName+"'";
	}
	console.log(sstra);
	$("#list4").jqGrid('setGridParam',{
		url:"./Order/selectBySql.do",
		type:"POST",
		postData:{"SearchSql":sstra},
        datatype:'json', 
          }).trigger("reloadGrid"); 

}
</script>
<script type="text/javascript">
$(document).ready(function(){
//	sstrval = $("#order_type").val();
	
//	if(sstrval == '' || sstrval == null ){
//		var sstra = '';
//	}else{
//		sstra = "and order_type ='"+sstrval+"'";
//	}

    $("#list4").jqGrid({
        url:"./Order/selectBySql.do",   //自动查询
        datatype:"json", 
        mtype:"POST",
        height:420,
    //    postData:{"SearchSql":sstra},
        autowidth:true,
       // colNames:['ID', '名称', 'qq','操作'],
       colNames:[ 
                 '订单编号', '创建订单时间', '销售机会编号 外键(销售机会表)','房间编号 外键(房间表)',
                 '付款方式名称','客户编号','客户名称','业务员编号', '业务员名称','订单类型','每平米房间单价',
                 '保证金','订单房间总价','购买面积','修改人','修改时间', '删除人','删除时间','删除状态' 
                    ],
       colModel:[
                 {name:'order_id',hidden:true,index:'order_id', width:'15%', align:'center'},
                 {name:'create_time',index:'create_time', width:'15%', align:'center'},
                 {name:'sale_chance_id',index:'sale_chance_id', width:'15%', align:'center', hidden:true},
                 {name:'room_id',index:'room_id', width:'15%', align:'center' ,hidden:true},
                 {name:'pay_type_name',index:'pay_type_name', width:'15%', align:'center'},
                 {name:'customer_id', hidden:true,index:'customer_id', width:'15%', align:'center'},
                 {name:'customer_name',index:'customer_name', width:'15%', align:'center'},
                 {name:'user_id', hidden:true,index:'user_id', width:'15%', align:'center'},
                 {name:'name',index:'name', width:'15%', align:'center'},
                 {name:'order_type',index:'order_type', width:'15%', align:'center'},
                 {name:'unit_price',index:'unit_price', width:'15%', align:'center'},
                 {name:'deposit',index:'deposit', width:'15%', align:'center'},
                 {name:'total',index:'total', width:'15%', align:'center'},
                 {name:'pay_area',index:'pay_area', width:'15%', align:'center'},
                 {name:'update_user',hidden:true,index:'update_user', width:'15%', align:'center'},
                 {name:'update_time',hidden:true,index:'update_time', width:'15%', align:'center'},
                 {name:'delete_user',hidden:true,index:'delete_user', width:'15%', align:'center'},
                 {name:'delete_time',hidden:true,index:'delete_time', width:'15%', align:'center'},
                 {name:'delete_state',hidden:true,index:'delete_state', width:'15%', align:'center'}
                 ],
        rownumbers:true,
        //altRows:true,
        //sortname:'createDate',
        //sortorder:'asc',
        viewrecords: true,
        rowNum:5,
        multiselect: true,//复选框     
        rowList:[2,4,6,8,10,12],
        jsonReader:{
            id: "blackId",
            repeatitems : false
        },
        pager:$('#gridPager')
    });
});
</script>
<script type="text/javascript">  
 
    function ajaxInsert(){  
	    window.location.href='addOrder.jsp';
    }
    
    function ajaxUpdate(){  
    	
    	var customer_id=$('#list4').jqGrid('getGridParam','selrow');
    	if(customer_id==null)
    	{
    	alert("请选择要修改的行");
    	return;
    	}
       var rowData = $('#list4').jqGrid('getRowData',customer_id);
       updateid=rowData.order_id;
       window.location.href="updateOrder.jsp?id="+updateid;
        
     }  
    function ajaxDelete(){  
    	
        var customer_id=$('#list4').jqGrid('getGridParam','selrow');
        if(customer_id==null)
        	{
        	alert("请选择要删除的行");
        	return;
        	}
        var rowData = $('#list4').jqGrid('getRowData',customer_id);
        delid=rowData.order_id;

        $.ajax({  
        data: {order_id:delid},  
        type:"Post",  
        dataType: 'json',  
         url:"./Order/deleteOrder.do",  
         error:function(data){  
             alert("出错了！！");  
         },  
        success:function(data){  
        	$("#list4").jqGrid('setGridParam',{ 
                datatype:'json', 
                postData:{'pageSize':10,'pageIndex':1,'SearchSql':""}, // 发送数据   
                page:1 
            }).trigger("reloadGrid"); 
        	 //alert("success:"+data.msg);  
            // $("#result").html(data.msg) ;  
         }  
         });  
     } 
    function ajaxSelect(){  
     /*   $.ajax({  
        data: {pageSize:10,pageIndex:1,SearchSql:""},  
        type:"Post",  
        dataType: 'json',  
         url:"selectBySql.do",  
         error :function(data){  
             alert("出错了！！");  
         },  
        success:function(data){  
          // alert("success:"+data);  
            // $("#result").html(data[0]);
        }
        }); 
     */
        var SearchSql ="";
        var customer_name=$("#customer_name").val();
        alert(customer_name);
        var tel=$("#tel").val();
        alert(tel);
          if(customer_name=="" && tel=="" ){
        	  SearchSql +="and delete_state='0'"
        	  $("#list4").jqGrid('setGridParam',{ 
                  datatype:'json', 
                  postData:{'SearchSql':SearchSql}, // 发送数据   
                  url:"./Customer/selectBySql.do",
                  page:1 
              }).trigger("reloadGrid"); 
          }else{
        	  if(customer_name!="" )
          	  {
          	     SearchSql +="  and customer_name like '%"+customer_name+"%'";
          	  }
        	  if(tel!="" )  
          	  {
          	     SearchSql +="  and tel='"+tel+"'";
          	  }
          	$("#list4").jqGrid('setGridParam',{ 
              datatype:'json', 
              postData:{'SearchSql':SearchSql}, // 发送数据     //  where name like '%"+$("#name").val()+"%'
              url:"./Customer/selectBySql.do",
              page:1 
          }).trigger("reloadGrid");  
          }
           
     } 
</script> 
<script type="text/javascript">
    function gotoaddreceive(){
        var customer_id=$('#list4').jqGrid('getGridParam','selrow');
        if(customer_id==null)
        	{
        	alert("请选择要签约的行");
        	return;
        	}
        var rowData = $('#list4').jqGrid('getRowData',customer_id);
        delid=rowData.order_id;
        window.location.href="addContract.jsp?id="+delid;
    }
    
</script>
</head>
<body>
<div id="gridPager"></div>
<div class="yboxwidth boxcenter ybox01" style="width: 100%">
<div class="ybox09" style="width: 100%" >
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <td  style="padding-left: 30px ">
       <table width="100%"  border="0"  cellspacing="0" cellpadding="0">
          <tr valign="top">
            <td class="ybox11td5" ></td>
            <td class="ybox11td6" >订单管理</td>
            <td class="ybox11td7"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td4"></td>    
             <td class="ybox11td4"></td>   
               <td class="ybox11td4"></td>   
                 <td class="ybox11td4" ></td>    
          </tr>
        </table>
        </td>
        </tr>
    </table>
  </div>
  
  <div class="ybox02">
    <table width="80%" border="0" cellspacing="0" cellpadding="0" class="margb4">
      <tr>
        <td class="ybox03td1"></td>
        <td class="ybox03td2"></td>
        <td class="ybox03td3"></td>
      </tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5"><div class="ybox05 margb8">
          <dl>
            <dt> <strong></strong>&nbsp;&nbsp;
              <!--   订单单号：<input type="text" id="customer_name"/> &nbsp;&nbsp;&nbsp;&nbsp; -->  
	        订单类型：<select style="width: 150px;" id="order_type" onchange="loadorder()">
	         <option value="">全部</option>
	        </select>
                 业务员名称：<select style="width: 150px;" id="customer_name" onchange="loadorder()">
	         <option value="">全部</option>
	        </select>
	                付款方式：<select style="width: 150px;" id="pay_type_name" onchange="loadorder()">
	         <option value="">全部</option>
	        </select>
	       <img onclick="ajaxSelect()" src="images/bottonselect.gif" width="50" height="20" style="vertical-align: middle;cursor: pointer;" />
	           </dt>
          </dl>
        </div>
          <div class="ybox07 margb2">
            
      <dl><table border="0" cellspacing="0" cellpadding="0" class="ybox07table" >
              <tr align="left">
                <td class="ybox07td1"><img src="images/op4_1.gif" /></td>
                <td><span style="cursor:pointer;" onclick="ajaxInsert()">添加订单信息</span></td>
                <td class="ybox07td2" width="10px"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td1"><img src="images/op4_3.gif" /></td>
                <td><span style="cursor:pointer;" onclick="ajaxDelete()">移除订单信息</span></td>
                <td class="ybox07td2" width="72%"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td2"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td1" ><img src="images/op6_1.gif" width="15" height="16"/></td>
                <td ><span style="cursor:pointer;" onclick="gotoaddreceive()">转签约</span></td>
                <td class="ybox07td2" ><img src="images/op4_0.gif"  /></td>

              </tr>
          </table>
          </dl>
          </div>	
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox06table" id="list4">
                
          </table>
        
        <td class="ybox03td6"></td>
      </tr>
      <tr>
        <td class="ybox03td7"></td>
        <td class="ybox03td8"></td>
        <td class="ybox03td9"></td>
      </tr>
    </table>
  </div>
</div>
</body>
</html>